import http from "../../util/http";
const  module={
  namespaced:true,
  state: {
    cityList:[],
    letterList:[],
  },
  mutations: {
    setCityList(state, list) {
      state.cityList = list;
    },
    setLetterList(state, list) {
      state.letterList = list;
    },
  },
  //处理异步操作
  actions: {
     //获取城市列表
     getCityList(store){
      http({
        url: "/gateway?k=1242047",
        headers: {
          "X-Host": "mall.film-ticket.city.list",
        },
      }).then((res) => {
        let data=res.data.data.cities;
        let letterArr = [];
        let alreadyArr = [];
        let mLetterList = [];
        for (let code = 65; code < 91; code++) {
          letterArr.push(String.fromCharCode(code));
        }
        for (let i = 0; i < letterArr.length; i++) {
          let newArray = data.filter((item) => {
            return item.pinyin.slice(0, 1).toUpperCase() === letterArr[i];
          });
          if (newArray.length != 0) {
            mLetterList.push(letterArr[i]);
            alreadyArr.push({
              type: letterArr[i],
              cityNameArray: newArray,
            });
          }
        }
        store.commit("setCityList",alreadyArr);
        store.commit("setLetterList",mLetterList);
      }); 
    },
  }
}
export default module;
// const  module={
//   namespaced:true,
//   state: {
   
//   },
//   mutations: {
   
//   },
//   //处理异步操作
//   actions: {
    
//   }
// }
// export default module;